﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class FND_SMN : RibbonForm
    {
        public FND_SMN()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        
        public string AccountCode { get; set; }
        public string EmployeeID { get; set; }
        public string AccountName { get; set; }
        
        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iRowIndex = gridView1.FocusedRowHandle;

            this.AccountCode = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["AcctCode"]).ToString();
            this.EmployeeID = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["EmpID"]).ToString();
            this.AccountName = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["AcctName"]).ToString();

            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            AccountManager oManager = new AccountManager();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable _table = oManager.BrowseAgentsByName(this.txtSearch.Text);
            oManager.Close();

            gridControl1.DataSource = _table;
            gridControl1.Refresh();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }

        private void FND_SMN_Load(object sender, EventArgs e)
        {

        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                AccountManager oManager = new AccountManager();
                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                DataTable _table = oManager.BrowseAgentsByName(this.txtSearch.Text);
                oManager.Close();

                gridControl1.DataSource = _table;
                gridControl1.Refresh();
            }
            if (e.KeyCode == Keys.Tab)
            {
                AccountManager oManager = new AccountManager();
                oManager.ConnectionString = this.ConnectionString;
                oManager.Open();
                DataTable _table = oManager.BrowseAgentsByName(this.txtSearch.Text);
                oManager.Close();

                gridControl1.DataSource = _table;
                gridControl1.Refresh();
            }
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }
    }
}
